package com.jgzx.redis.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * redis配置
 */
@Configuration
@EnableCaching
public class RedisConfig{

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private int port;

    @Value("${spring.redis.password}")
    private String password;

    @Value("${spring.redis.timeout}")
    private int timeout;

    @Bean
    public JedisPoolConfig getRedisConfig(){
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);//资源池中最大连接数
        config.setMaxIdle(100);//资源池允许最大空闲的连接数
        config.setMinIdle(5);//资源池确保最少空闲的连接数
        config.setTestWhileIdle(true);//是否开启空闲资源监测
        return config;
    }

    /**
     * 0号库
     * @return
     */
    @Bean(name = "jedisPool0")
    public JedisPool getJedisPool0(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,0);
        return pool;
    }

    /**
     * 1号库
     * @return
     */
    @Bean(name = "jedisPool1")
    public JedisPool getJedisPool1(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,1);
        return pool;
    }

    /**
     * 2号库
     * @return
     */
    @Bean(name = "jedisPool2")
    public JedisPool getJedisPool2(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,2);
        return pool;
    }

    /**
     * 3号库
     * @return
     */
    @Bean(name = "jedisPool3")
    public JedisPool getJedisPool3(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,3);
        return pool;
    }

    /**
     * 4号库
     * @return
     */
    @Bean(name = "jedisPool4")
    public JedisPool getJedisPool4(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,4);
        return pool;
    }

    /**
     * 5号库
     * @return
     */
    @Bean(name = "jedisPool5")
    public JedisPool getJedisPool5(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,5);
        return pool;
    }

    /**
     * 6号库
     * @return
     */
    @Bean(name = "jedisPool6")
    public JedisPool getJedisPool6(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,6);
        return pool;
    }

    /**
     * 7号库
     * @return
     */
    @Bean(name = "jedisPool7")
    public JedisPool getJedisPool7(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,7);
        return pool;
    }

    /**
     * 8号库
     * @return
     */
    @Bean(name = "jedisPool8")
    public JedisPool getJedisPool8(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,8);
        return pool;
    }

    /**
     * 9号库
     * @return
     */
    @Bean(name = "jedisPool9")
    public JedisPool getJedisPool9(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,9);
        return pool;
    }

    /**
     * 10号库
     * @return
     */
    @Bean(name = "jedisPool10")
    public JedisPool getJedisPool10(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,10);
        return pool;
    }

    /**
     * 11号库
     * @return
     */
    @Bean(name = "jedisPool11")
    public JedisPool getJedisPool11(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,11);
        return pool;
    }

    /**
     * 12号库
     * @return
     */
    @Bean(name = "jedisPool12")
    public JedisPool getJedisPool12(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,12);
        return pool;
    }

    /**
     * 13号库
     * @return
     */
    @Bean(name = "jedisPool13")
    public JedisPool getJedisPool13(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,13);
        return pool;
    }

    /**
     * 14号库
     * @return
     */
    @Bean(name = "jedisPool14")
    public JedisPool getJedisPool14(){
        JedisPoolConfig config = getRedisConfig();
        JedisPool pool = new JedisPool(config,host,port,timeout,password,14);
        return pool;
    }

}
